package CommonInterface;

import java.util.Arrays;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-04-08
 * Time: 13:54
 * To BE A Better Person-2020-3-2
 */
//hhh
class Student implements Comparable<Student> {
    public int id;
    public String name;

    public Student(String name, int id) {
        this.id = id;
        this.name = name;
    }


    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    //对于每次要改，很不方便
    @Override
    public int compareTo(Student o) {
        if (this.id > o.id) {
            return 1;
        } else if (this.id == o.id) {
            return 0;
        } else {
            return -1;
        }

    }
}
public class TestDemo {
    public static void main(String[] args) {
        Student[] students = new Student[5];
        students[0] = new Student("kris", 20);
        students[1] = new Student("krit", 23);
        students[2] = new Student("Dottie", 22);
        students[3] = new Student("Kobe", 30);
        students[4] = new Student("krik", 24);
        System.out.println(Arrays.toString(students));
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));

    }
}
